﻿#include "app_home_view.h"

// 组件声明，必须有
app_home_view_t app_home_view;

// 样式声明，注意需要在使用结束后释放
static lv_style_t style;    // 全局样式

/**
 * @brief 样式初始化
*/
static void style_init() {
    lv_style_init(&style);
    lv_style_set_bg_color(&style, lv_color_black());
    lv_style_set_pad_top(&style, 10);
    lv_style_set_pad_bottom(&style, 10);
    lv_style_set_pad_left(&style, 10);
    lv_style_set_pad_right(&style, 10);
    lv_style_set_text_color(&style, lv_palette_main(LV_PALETTE_RED));
    lv_style_set_text_letter_space(&style, 0);
    lv_style_set_text_line_space(&style, 20);
    lv_style_set_text_decor(&style, LV_TEXT_DECOR_NONE);
    lv_style_set_text_font(&style, &lv_font_montserrat_16);
    lv_style_set_text_color(&style, lv_color_white());
}

/**
 * @brief 样式释放
*/
static void style_delete() {
    lv_style_reset(&style);
}

/**
 * @brief 创建界面
 * @param root 
*/
void app_home_view_create(lv_obj_t* root)
{
    style_init();

    if (root == NULL)
    {
        app_log_error("page root is null! please check memory.");
    }
    lv_obj_add_style(root, &style, 0);
    // 采用基础布局
    lv_obj_set_layout(root, LV_LAYOUT_FLEX);
    lv_obj_set_flex_flow(root, LV_FLEX_FLOW_ROW_WRAP);

    app_home_view.title = lv_label_create(root);
    lv_obj_add_style(app_home_view.title, &style, 0);
    lv_label_set_text_fmt(app_home_view.title, "This is app_home_view!");

    app_home_view.back = lv_btn_create(root);
    lv_obj_t* l = lv_label_create(app_home_view.back);
    lv_label_set_text(l, "to system");
}

/**
 * @brief 页面销毁，挂在root下的页面，都会自动销毁
 * 此处主要销毁样式
*/
void app_home_view_delete() {
    style_delete();
}
